package com.magicsoft.share.ui.my;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.magicsoft.share.R;
import com.magicsoft.share.base.BaseActivity;
import com.magicsoft.share.constant.Constant;
import com.magicsoft.share.presenter.my.OldPasswordPresenter;
import com.magicsoft.share.ui.main.InputPasswordActivity;
import com.magicsoft.share.utils.AlerterUtils;
import com.magicsoft.share.view.my.IOldPasswordView;

import butterknife.BindView;
import butterknife.OnClick;

public class OldPasswordActivity extends BaseActivity<IOldPasswordView, OldPasswordPresenter> implements IOldPasswordView {


    @BindView(R.id.view_top)
    View viewTop;
    @BindView(R.id.ibtn_left)
    ImageButton ibtnLeft;
    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ibtn_right)
    ImageButton ibtnRight;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.edt)
    EditText edt;
    @BindView(R.id.btn)
    Button btn;
    private String passwordStr;

    @Override
    public OldPasswordPresenter initPresenter() {
        return new OldPasswordPresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_old_password;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {

        tvTitle.setText("");
    }

    @Override
    public void requestData() {

    }


    @OnClick({R.id.ibtn_left, R.id.btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ibtn_left:
                finish();
                break;
            case R.id.btn:
                checkPassword();
                break;
        }
    }

    private void checkPassword() {
        passwordStr = edt.getText().toString().trim();
        if (TextUtils.isEmpty(passwordStr)) {
            AlerterUtils.warning(this, "请输入密码");
        } else {
            mPresenter.checkOldPassword(passwordStr);

        }

    }

    @Override
    public void checkOldPasswordSuccess() {
        Intent intent = new Intent(this, InputPasswordActivity.class);
        intent.putExtra("inputPasswordType", Constant.INPUT_PASSWORD_MODIFY);
        intent.putExtra("oldPassword", passwordStr);
        startActivity(intent);
        finish();
    }
}
